package com.dk.controller;

import com.dk.pojo.Location;
import com.dk.pojo.Warehouse;
import com.dk.result.PageResult;
import com.dk.result.Result;
import com.dk.result.ResultConstant;
import com.dk.service.LocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("location")
@Api(tags = "库区接口文档")
public class LocationController {

    @Autowired
    private LocationService locationService;

    @GetMapping("getLocationInfo")
    @ApiOperation("库区模糊查询和分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数"),
            @ApiImplicitParam(name = "name", value = "库区名称"),
            @ApiImplicitParam(name = "wid", value = "仓库id",required = true)
    })
    public Result getLocationInfo(@RequestParam(defaultValue = "1")Integer pageNum,
                                   @RequestParam(defaultValue = "5") Integer pageSize,
                                   String name,Integer wid){
        PageResult<Location> result = locationService.getLocationInfo(pageNum,pageSize,name,wid);
        return new Result(ResultConstant.CODE,ResultConstant.MESSAGE,result);
    }

    @PostMapping("addLocation")
    @ApiOperation("库区增加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "库区编号",required = true),
            @ApiImplicitParam(name = "name", value = "库区名称",required = true),
            @ApiImplicitParam(name = "area", value = "库区面积",required = true),
            @ApiImplicitParam(name = "token", value = "登录后返回的token串",required = true),
            @ApiImplicitParam(name = "wid", value = "仓库的id",required = true),
            @ApiImplicitParam(name = "remark", value = "备注")
    })
    public Result addLocation(Location location,@RequestHeader String token){
        if(token == null || "".equals(token)){
            return new Result(ResultConstant.TOKEN_CODE, ResultConstant.TOKEN_MESSAGE);
        }
        return locationService.addLocation(location,token);
    }

    @PutMapping("updateLocation")
    @ApiOperation("库区修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lid", value = "库区id",required = true),
            @ApiImplicitParam(name = "code", value = "库区编号"),
            @ApiImplicitParam(name = "name", value = "库区名称"),
            @ApiImplicitParam(name = "area", value = "库区面积"),
            @ApiImplicitParam(name = "token", value = "登录后返回的token串",required = true),
            @ApiImplicitParam(name = "wid", value = "仓库的id"),
            @ApiImplicitParam(name = "remark", value = "备注")
    })
    public Result updateLocation(Location location,@RequestHeader String token){
        if(token == null || "".equals(token)){
            return new Result(ResultConstant.TOKEN_CODE, ResultConstant.TOKEN_MESSAGE);
        }
        return locationService.updateLocation(location,token);
    }

    @DeleteMapping("deleteLocation")
    @ApiOperation("库区删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lid", value = "库区id",required = true)
    })
    public Result deleteLocation(Integer lid){
        locationService.deleteLocation(lid);
        return new Result(ResultConstant.CODE,ResultConstant.MESSAGE);
    }
}